package com.bondex.charter.service;

import com.bondex.charter.maindata.pojo.api.BaseComContainerTypeVO;
import com.bondex.charter.maindata.pojo.dto.BaseComContainerTypeDTO;
import com.bondex.charter.maindata.service.MainDataService;
import com.bondex.global.pojo.JsonDataT;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 * 描述：TODO
 * </pre>
 *
 * @author： wh
 * @date: 2021/9/18 10:04
 */
@Service
public class MainDataCacheService {

    @Value("${charter.basicData.address}")
    private String mainDataUrl;

    protected Logger log = LoggerFactory.getLogger(MainDataCacheService.class);

    public static List<BaseComContainerTypeVO> BASECOM_CONTAINERTYPE_DTOLIST = new ArrayList<BaseComContainerTypeVO>();

    public List<BaseComContainerTypeVO> getBaseComContainerTypeDTOList(String token){
        if (CollectionUtils.isEmpty(BASECOM_CONTAINERTYPE_DTOLIST)) {
            //设置箱型基础数据查询条件
            BaseComContainerTypeDTO baseComContainerTypeDTO = new BaseComContainerTypeDTO();
            //箱型审核通过
            baseComContainerTypeDTO.setDataType("auditPass");
            baseComContainerTypeDTO.setLimit(-256);
            //查询方式为0-条件查询，标志位为0未删除
            baseComContainerTypeDTO.setQueryMethod("0");
            baseComContainerTypeDTO.setDelFlg("0");
            if (StringUtils.isBlank(token)) {
                log.info("token为空，获取箱型信息失败");
            }
            baseComContainerTypeDTO.setToken(token);
            MainDataService mainDataService = new MainDataService(mainDataUrl);
            JsonDataT<List<BaseComContainerTypeVO>> jsonDataT = null;
            try {
                jsonDataT = mainDataService.getComContainerType(baseComContainerTypeDTO);
            } catch (Exception e) {
                log.info("获取箱型信息失败");
            }
            BASECOM_CONTAINERTYPE_DTOLIST = jsonDataT.getData();
        }else {
            return BASECOM_CONTAINERTYPE_DTOLIST;
        }
        return BASECOM_CONTAINERTYPE_DTOLIST;
    }
}
